package jdos.hardware;

import jdos.Dosbox;
import jdos.gui.Main;
import jdos.gui.Render;
import jdos.hardware.VGA_memory.VRAM;
import jdos.ints.Int10_modes;
import jdos.misc.Log;
import jdos.misc.setup.Config;
import jdos.types.LogSeverities;
import jdos.types.LogTypes;
import jdos.util.IntPtr;
import jdos.util.StringHelper;

public class VGA_draw {

	static int outWriteOff;

	public static void writeb(/*HostPt*/int address, /*Bit8u*/ int value) {
		Main.int_rawImageData2[outWriteOff + address] = Main.cmap[value & 0xFF];
	}

	public static void VGA_Draw_Linear_Line(/*Bitu*/int vidstart, int width) {

		int draw = 0;
		for (/*Bitu*/int x = 0; x < width; x++) {
			/*Bitu*/int val0 = VRAM.readb(vidstart + x);
			writeb(draw, val0);
			draw++;
		}

	}

	public static void Draw() {
		try {


			int width = 320;
			int address_add = VGA_crtc.scan_len * 8;//VGA.vga.config.scan_len*8;

			int lines_total = VGA_crtc.scan_len == 40 ? 200: 240;

			outWriteOff = 0;
			int address = VGA_crtc.scan_len == 40 ? 0: 32*address_add;
			for (int i = 0; i < lines_total; i++) {

				VGA_Draw_Linear_Line(address, width);

				outWriteOff += 640;

				address += address_add;
			}
			Main.GFX_EndUpdate();
			VGA_misc.flg = 1;
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}
//
//	public static void VGA_Draw_Linear_Line(/*Bitu*/int vidstart, int width) {
//
//		int draw = 0;
//		for (/*Bitu*/int x = 0; x < width; x++) {
//			/*Bitu*/int val0 = VRAM.readb(vidstart + x);
//			writeb(draw, val0);
//			draw++;
//			writeb(draw, val0);
//			draw++;
//		}
//
//	}
//
//	public static void Draw() {
//		try {
//
//			int address_line_total = 0;
//
//			int width = 320;
//			int address_add = 40 * 8;
//			address_line_total = 2;
//
//			int lines_total = 480;
//
//			outWriteOff = 0;
//			int address_line = 0;
//			int address = 0;
//			for (int i = 0; i < lines_total; i++) {
//
//				VGA_Draw_Linear_Line(address, width);
//
//				outWriteOff += 640;
//
//				address_line++;
//				if (address_line >= address_line_total) {
//					address_line = 0;
//					address += address_add;
//				}
//			}
//			Main.GFX_EndUpdate();
//			VGA_misc.flg = 1;
//		} catch (Throwable t) {
//			t.printStackTrace();
//		}
//	}

}
